<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>送花</title>
</head>

<body>
    <script>
        // 浏览器 上网代理，运行页面时，JS 的宿主环境
        // 作用域
        function func() {
            let c = 3; //局部变量
        }
        // 全局变量
        // 变量名 地址的映射 属于运行环境的作用域
        // 空间大小 整数空间
        // let d; //undefined 没有值，类型未定义
        // var a = 1; //var  js变量常量声明的关键字
        // let b = 2; //es6(2015) 之后提供的let const
        // const name = "yangxiang";
        // let age = 19;
        // const hometown = "丰城";
        // const sex = 'nan';
        // 对象 字面量
        /*
        函数名大写，类
        */
        //    class Flower{
        //        constructor(){

        //        }
        //    }
        function Flower(type, num) {
            // 指针
            // this 指向构造函数运行
            console.log(this);
            this.type = type;
            this.num = num;

        }
        // 构造对象时就指向那个
        const ych = new Flower('玫瑰花', 3); // 用new 产生一个this
        console.log(ych.type);
        const rose = new Flower('油菜花', 1);
        console.log(rose.type);
        console.log(rose);
        const obj = {
            name: 'yang',
            age: 19,
            hometown: '丰城',
            sex: '男',
            gf: null,
            work_status: undefined,
            sendFlower(target) {
                const flower = new Flower('红玫瑰', 99);
                // console.log(this); //指向对象
                // console.log(target);
                target.receiveFlower(this, flower);
            }
        }
        const xiaoming = {
            name: 'xiaoming',
            age: 18,
            receiveFlower(sender, flower) {
                console.log(this.name + '收到了' + sender.name + '送的花' + flower.num + '朵' + flower.type);
            }

        }
        const xiaohong = {
            name: 'xiaohong',
            hometown: '九江',
            receiveFlower(sender, flower) {
                // console.log("你是杨？");
                // target.sendFlower(xiaoming);
                xiaoming.receiveFlower(sender, flower);
            }
        }
        obj.sendFlower(xiaohong);
        // xiaohong.receiveFlower(obj);
    </script>
</body>

</html>